﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jumpton.SFA.Server.BusinessRule.MasterData;
using Jumpton.SFA.Server.Entity;
using Jumpton.Persistent;

public partial class WareHouse_SelectProduct : PageBase
{
    ObjectTable ot;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetManuType();
            GetCategoryType();
            GetBrandType();
            GetFormType();
            GetProductsBind();

        }
    }

    public void GetProductsBind()
    {
        DataSet ds = ProductManager.GetProductDynamicForJumpton(txtCustomer.Text,
        ddlCategroy.SelectedValue,
        ddlBrand.SelectedValue,
        ddlManu.SelectedValue,
        ddlForm.SelectedValue,
        MyStateManager.DomainID, "1", "0");
        GridPager1.DataSource = ds.Tables[0];
        GridPager1.GridView = GridView1;
        GridPager1.BindData();
        GridPager1.Visible = GridView1.Rows.Count > 0;
    }


    #region 绑定品牌
    public void GetBrandType()
    {
        ddlBrand.DataTextField = "BrandName";
        ddlBrand.DataValueField = "BrandCode";
        ot = BrandManager.GetBrands(MyStateManager.DomainID);
        if (ot != null)
        {
            ot.BillDataTable.DefaultView.RowFilter = "ACTIVE=1";
            ddlBrand.DataSource = ot.BillDataTable.DefaultView;
            ddlBrand.DataBind();
        }

        ddlBrand.Items.Insert(0, new ListItem(Resources.language.ddl_All, ""));
    }
    #endregion

    #region 绑定系列
    public void GetFormType()
    {
        ddlForm.DataTextField = "FormName";
        ddlForm.DataValueField = "FormCode";
        ot = FormManager.GetFORMS(MyStateManager.DomainID);
        if (ot != null)
        {
            ot.BillDataTable.DefaultView.RowFilter = "ACTIVE=true";
            ddlForm.DataSource = ot.BillDataTable.DefaultView;
            ddlForm.DataBind();
        }
        ddlForm.Items.Insert(0, new ListItem(Resources.language.ddl_All, ""));
    }
    #endregion

    #region 绑定制造商
    public void GetManuType()
    {
        ddlManu.DataTextField = "ManuName";
        ddlManu.DataValueField = "ManuCode";
        ot = ManufacturersManager.GetManus(MyStateManager.DomainID);
        if (ot != null)
        {
            ot.BillDataTable.DefaultView.RowFilter = "ACTIVE=1";
            ddlManu.DataSource = ot.BillDataTable.DefaultView;
            ddlManu.DataBind();
        }
        ddlManu.Items.Insert(0, new ListItem(Resources.language.ddl_All, ""));
    }
    #endregion

    #region 绑定品类
    public void GetCategoryType()
    {
        ddlCategroy.DataTextField = "CategoryName";
        ddlCategroy.DataValueField = "CategoryCode";
        ot = CategoryManager.GetCategories(MyStateManager.DomainID);
        if (ot != null)
        {
            ot.BillDataTable.DefaultView.RowFilter = "ACTIVE=1";
            ddlCategroy.DataSource = ot.BillDataTable.DefaultView;
            ddlCategroy.DataBind();
        }
        ddlCategroy.Items.Insert(0, new ListItem(Resources.language.ddl_All, ""));
    }
    #endregion

    protected void btnQuery_Click(object sender, EventArgs e)
    {
        GetProductsBind();
    }

    #region 制造商改变事件
    protected void ddlManu_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddlBrand.DataTextField = "BrandName";
        ddlBrand.DataValueField = "BrandCode";
        DataSet ds = BrandManager.GetBrandsListDaynamic(ddlCategroy.SelectedValue, ddlManu.SelectedValue, MyStateManager.DomainID);
        ddlBrand.DataSource = ds;
        ddlBrand.DataBind();
        ddlBrand.Items.Insert(0, new ListItem(Resources.language.ddl_All, ""));
    }
    #endregion

    #region 品类改变事件
    protected void ddlCategroy_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddlBrand.DataTextField = "BrandName";
        ddlBrand.DataValueField = "BrandCode";
        DataSet ds = BrandManager.GetBrandsListDaynamic(ddlCategroy.SelectedValue, ddlManu.SelectedValue, MyStateManager.DomainID);
        ddlBrand.DataSource = ds;
        ddlBrand.DataBind();
        ddlBrand.Items.Insert(0, new ListItem(Resources.language.ddl_All, ""));
    }
    #endregion

    public void GridViewToolbarUserControl1_OnGVTBSetColumnsButtonEvent(object sender, EventArgs e)
    {
        GetProductsBind();
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GetProductsBind();
    }
}